﻿// MessageKernel.cpp : 定义 DLL 应用程序的导出函数。
//

#include "core/comdefs.h"
#include "core/common_types.h"
#include "source/network_service_impl.h"

using namespace qb;

#ifdef _MSC_VER
struct CClassFactory : public IClassFactory {
  virtual HRESULT STDMETHODCALLTYPE CreateInstance(IUnknown* pUnkOuter,
                                                   REFIID riid,
                                                   void** ppvObject) {
    if (riid == IID_INetworkService) {
      CNetworkServiceImpl* p = new CUnknownObject<CNetworkServiceImpl>;
      p->AddRef();

      *ppvObject = p;

      return S_OK;
    }

    return E_NOTIMPL;
  }

  virtual HRESULT STDMETHODCALLTYPE LockServer(BOOL fLock) { return E_NOTIMPL; }
};

extern "C" S_QBNET_EXPORT HRESULT __stdcall QtDllGetClassObject(REFCLSID rclsid,
                                                                REFIID riid,
                                                                LPVOID* ppv) {
  if (CLSID_NetworkService == rclsid) {
    if (IID_IClassFactory == riid) {
      CClassFactory* pf = new CUnknownObject<CClassFactory>;
      pf->AddRef();

      *ppv = pf;
      return S_OK;
    }
  }
  return E_NOTIMPL;
}

#else

STDAPI NetworkService_CreateObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv) {
  if (CLSID_NetworkService == rclsid) {
    if (IID_INetworkService == riid) {
      CNetworkServiceImpl* p = new CUnknownObject<CNetworkServiceImpl>;
      p->AddRef();

      *ppv = p;

      return 0;
    }
  }

  return -1;
}

#endif
